package com.echat.serviceapigateway.zuul.service;

import com.echat.serviceapigateway.zuul.CustomRouteLocator;
import org.apache.commons.lang.IllegalClassException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.netflix.zuul.filters.Route;
import org.springframework.cloud.netflix.zuul.filters.RouteLocator;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by chenmohan on 2018/10/16
 *
 * @description
 */
@Service
public class GatewayRefreshService {

    @Autowired
    RouteLocator routeLocator;

    public void refresh(){
        if(routeLocator instanceof CustomRouteLocator){
            CustomRouteLocator routeLocator = (CustomRouteLocator) this.routeLocator;
            routeLocator.manualRefresh();
        }else{
            throw new IllegalClassException("");
        }
    }

    public List<Route> routeList(){
       return routeLocator.getRoutes();
    }

}
